package com.example.demo.web.controller;


import com.example.demo.bean.Counsel;
import com.example.demo.bean.Module;
import com.example.demo.service.IModuleService;
import com.example.demo.utils.Message;
import com.example.demo.utils.MessageUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


@RestController
@RequestMapping("/module")
@Validated
public class ModuleController {
    @Autowired
    private IModuleService moduleService;
    @GetMapping("query")
    public Message query(String name, String status) {
        List<Module> list = moduleService.query(name,status);
        return MessageUtil.success(list);
    }

    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Module module) {
        moduleService.saveOrUpdate(module);
        return MessageUtil.success("保存成功");
    }

    @DeleteMapping("deleteById")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="用户编号",required=true,paramType ="query")
    })
    public Message deleteById(@NotNull long id) {
        moduleService.deleteById(id);
        return MessageUtil.success("删除成功");
    }

}
